var ismore=1;//控制单发还是群发单显  1是单发，2是群发
var sendDate="";//定时发送设置
var aduncts=new Map();//附件
var fileIndex=0;//用来控制下标
var fileNameIndex=new Map();//用来删除附件的图形
var email=null;//用来回复、转发
var temps=null;//用来控制签名
var deplay=null;//用户设置
var email_id=0.1;//草稿箱邮件id
$(function(){
    $("#addtheme").hide();
    $("a[tooltip]").each(function(){
        var t = $(this).attr('tooltip');
        $(this).tooltip({
            text:t
        });
    });
});

layui.use(['jquery', 'tagsInput','dropdown','form'], function () {
    var dropdown = layui.dropdown;
    var upload = layui.upload;
    var laydate = layui.laydate;
    var $ = layui.jquery;
    var tagsInput = layui.tagsInput;
    // 输入列表提示
    $('#recipient').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true
    });
    $('#ccpeople').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });
    $('#closesendpeople').tagsInput({
        // skin: 'tagsinput-default',
        autocomplete_url: 'email/selectDimEmailAddress',
        removeWithBackspace: true

    });

    // 监听菜单点击
    dropdown.onFilter('more', function (event) {

    })
    laydate.render({
        elem: '#test1'
        ,type: 'datetime'
    });
    //指定允许上传的文件类型
    upload.render({
        elem: '#tjfj'
        ,url: 'email/uploadAdjunctFile' //改成您自己的上传接口
        ,method:"POST"
        ,multiple:true
        ,accept: 'file' //普通文件
        ,done: function(res){
            if(res.data!=null){
              var fileName= res.data[0];
              var filePath=res.data[1];
              aduncts.set(fileName,filePath);
              fileNameIndex.set(fileIndex,fileName);
                layer.msg('上传成功');
                $("#adjuncts").append("<div class=\"item\" title='"+fileName+"' id='adjunct"+fileIndex+"'><div>\n" +
                    "<img alt=\"\" src=\"statics/img/"+adjunctClass(fileName)+".png\">\n" +
                    "</div><div style=\"padding:6px;\">\n" +
                    "<p><a>"+fileName+"</a></p><div>\n" +
                    "</div></div>\n" +
                    "<a class=\"close\" onclick='deleteAdjunct(\""+fileName+"\")'>x</a></div>");
                fileIndex++;
            }

        }
    });
    getTemplate();//获取签名
    function  getTemplate() {
        $.ajax({
            url: 'email/showTemplate?type=2',
            type: 'GET',
            success: function (date) {
                var templates= date.data
                temps=templates
                dropdown.suite("#template", {
                    template: "#insertthesignature",
                    success: function ($dom) {
                        for(let i in templates){
                            var name =templates[i].template_name
                            var id=templates[i].template_id
                            $("#email_template").append("<div class=\"menu-item\">\n" +
                                "<a href=\"javascript:;\" lay-event=\"emailtemplate\" onclick='setTemp("+id+")'><span class=\"\">"+name+"</span></a></div>\n")
                        }
                        // 当自定义内容模板初始化完成
                        // 此方法会调用. 传入的$dom就
                        // 包含了你的模板的内容，通过它
                        // 你可以在这里进行模板内其他组
                        // 件的初始化。
                    },
                });
                addMo(templates)
            }
        });

    }

    //草稿箱不需要加默认签名
    function  addMo(templates) {
        var cao=getQueryString("caogao");
        if(cao!=2){
            CKEDITOR.on('instanceReady', function (e) {
                // alert(e.editor.name+'加载完毕！')
                for(let i in templates){
                    if(templates[i].templateStatue==1){
                        CKEDITOR.instances.textarea.insertHtml(templates[i].template_text);
                    }
                }
            });
        }

    }

});
function adjunctClass(fileName) {
   var ff=fileName.split(".");
   var f1=ff[ff.length-1];
   return f1;
}
function deleteAdjunct(fileName) {
    //1.ajax删除附件，2.删除图标
    $.ajax({
        url: 'email/deleteTempAdjunct',
        type: 'get',
        contentType: "application/json; charset=utf-8",
        data: {
            "fileName":fileName,
            "filePath":aduncts.get(fileName)
        },
        success: function (date) {
            //修改当前页面的adjunts
            aduncts.delete(fileName);
            var index =0;//查找index
            for(var i=0;i<fileNameIndex.size;i++){
                if(fileNameIndex.get(i)==fileName){
                    index=i;
                }
            }
            $("#adjunct"+index).remove();
        }
    });
}
function doCxr(ti){
    var t = $(ti).text();
    if(t == '抄送'){
        $(ti).text('删除抄送');
        $("#cxr").show();
    }else{
        $(ti).text('抄送');
        $("#cxr").hide();
    }
}
function doMxr(ti){
    var t = $(ti).text();
    if(t == '密送'){
        $(ti).text('删除密送');
        $("#msr").show();
    }else{
        $(ti).text('密送');
        $("#msr").hide();
    }
}

function doQfdx(ti){
    var t = $(ti).text();
    if(t == '群发单显'){
        ismore=2;
        $("#addtheme").show();
        $(ti).text('删除群发单显');
        $("#sjr").text('群发单显');
    }else{
        ismore=1;
        $("#addtheme").hide();
        $(".collectaset div.zt").remove()
        $(ti).text('群发单显');
        $("#sjr").text('收件人');
    }
}
function dointer() {
    layer.open({
        type: 2
        ,title: "内部转发"
        ,area:  ['70%', '70%']
        ,shade: 0.8
        ,btnAlign: 'c'
        ,moveType: 1 //拖拽模式，0或者1
        ,content: "views/jsp/BasicData/email/internalforwarding.jsp"
    });
}
function doRegularly() {
    layer.open({
        type: 1
        ,title: "设置定时发送"
        ,area:  ['420px', '240px']
        ,btn: ['确定', '取消']
        ,skin: 'layui-layer-rim' //加上边框
        ,content:  $("#doRegularly")
        ,yes: function(index, layero){
            //按钮【按钮一】的回调
            sendDate=$("#test1").val();
            layer.closeAll();
        }
        ,btn2: function(index, layero){
            //按钮【按钮二】的回调

            //return false 开启该代码可禁止点击该按钮关闭
        }
    });
}
function searchs(types) {
    layer.open({
        type: 2
        ,title:types==1?"选择收件人":"选择抄送人"
        ,area:  $(window).width() < 458 ? "['100%', '100%']":['75%', '75%']
        ,shade: 0.8
        ,btn: ['确定', '取消']
        ,btnAlign: 'c'
        ,moveType: 1 //拖拽模式，0或者1
        ,content: 'views/jsp/BasicData/email/searchs.jsp'
        ,yes: function(index, layero){
            debugger
            var res = window["layui-layer-iframe"+index].callbackdata();
            if(res.address==""||res.address==null){
                   layer.msg("未选择收件人")
            }else{
                if (types==1){
                    $("#recipient").importTags(res.address)
                }else {
                    $("#ccpeople").importTags(res.address)
                }

            layer.closeAll();
            }
        }
        ,btn2: function(index, layero){
            layer.closeAll();
        }
    });
}
function addtheme(){
    var zjhtml = '<div class="ipt zt">'+
        '<span>主题'+($(".zt").length+2)+'</span>'+
        '<input placeholder="请输入主题" class="emailSubject"/>'+
       ' <span style="float:right; ">0/100</span>'+
        '<i style="margin-left: 5px" onclick="deltheme()" class="layui-icon">&#xe616;</i>'+
    '</div>';
    $(".collectaset").append(zjhtml);
}
function deltheme(){
    $(".collectaset div.zt:last-child").remove()
}

function showBadgeWindow(){

        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);




}

function closeEdite() {
    if(confirm("是否关闭当前页面")){
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

}

function showCreateBadgeWindow(){
    layer.open({
        btn: ['确定', '取消'],
        type: 1,
        title:'新增标签',
        skin: 'layui-layer-rim', //加上边框
        area: ['420px', '240px'], //宽高
        content: $("#CreateBadgeWindow")
    });
    $("#CreateBadgeWindow").show();
}
function systemfiles() {
    layer.open({
        type: 2
        ,title: false //不显示标题栏
        ,closeBtn: false
        ,area:  $(window).width() < 458 ? "['100%', '100%']":['75%', '75%']
        ,shade: 0.8
        ,btn: ['确定', '取消']
        ,btnAlign: 'c'
        ,moveType: 1 //拖拽模式，0或者1
        ,content: 'views/jsp/BasicData/files.jsp'
        ,yes: function(index, layero){
            //按钮【按钮一】的回调
        }
        ,btn2: function(index, layero){
            //按钮【按钮二】的回调

            //return false 开启该代码可禁止点击该按钮关闭
        }
    });
}


//获取url中的id
function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}
//用户所属邮箱控制
function getpop3ID() {
    $.ajax({
        url: 'email/selectSmtp',
        type: 'GET',
        async:false,
        success: get,
    });
}
var smtp="";
//显示邮箱信息到页面
function get(date) {
    smtp = date.data;
    for(let i in smtp){
        $('#user-smtp').append("<option value='"+smtp[i].smtp_id+"' text='"+smtp[i].email_adress+"'>"+smtp[i].smtp_name+"</option>");
    }
    form.render();
}

function getDate() {
    var val = CKEDITOR.instances.textarea.getData();
    return val;
}

function setDate(ht){
    CKEDITOR.instances.textarea.setData(ht);
}
function setTemp(id) {
    for(let i in temps){
        if(temps[i].template_id==id){
            CKEDITOR.instances.textarea.insertHtml(temps[i].template_text)
        }
    }
}
//发送中界面
function loadfn(n=0) {
    return layer.load(n, {
        content: '发送中...',
        shade: [0.1, '#000'] //0.1透明度的白色背景
    })
}
function sendEmail() {
    var message = getEmail();
    let index=loadfn(0,"发送中")
    $.ajax({
        url: 'email/sendEmail',
        type: 'POST',
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(message),
        success: function (date) {
            if(answerOrRelay!=0){
                var title
                if(answerOrRelay==1){
                    title="已回复";
                    addTag(answerOrRelayId,title,"red")
                }else{
                    title="已转发";
                    addTag(answerOrRelayId,title,"#f1e557")
                }

            }
            layer.close(index);
            if(date.data=="已进入定时发送序列"){
                layer.msg(date.data, {icon:1, time:2000,shift: 6,},function(){
                    window.location.reload();
                })
            }else if(date.data=="已进入延时发送序列"){
                layer.msg(date.data, {icon:1, time:2000,shift: 6},function(){
                    window.location.reload();
                })
            }else if(date.data=="发送成功"){
                layer.msg(date.data, {icon:1, time:2000,shift: 6},function(){
                    window.location.reload();
                })
            }else{
                layer.msg(date.data, {icon:2, time:2000,shift: 6,function(){
                 }})
            }
        }
    });
}

function getEmail() {
    var sendAddres=new Map();
    var copyAddress=new Array();
    var darkAddress=new Array();
    var sendAddress=new Map();
    var pictures=new Map();
    var subjects=new Array();
    var pop= $("select[id=user-smtp]").val();
    //主题
    var subs = document.getElementsByClassName('emailSubject');//数组
    var len=subs.length;
    for(i=0;i<len;i++){
        subjects.push(subs[i].value);
    }
    var subject=subjects[0];
    var substring = "<";
    //获取到发送地址
    var sj=$("#recipient").val();//收件人  张某<804422090@qq.com>,
    if(sj!=null){
        var ssj=sj.split(",");
        for(let i in ssj){
            if(ssj[i].indexOf(substring)==-1){
                sendAddres.set(i,ssj[i]);
                sendAddress.set(i,ssj[i]);
            }else{
                var split1 = ssj[i].split("<");
                var sendN=split1[0];
                var sendA=split1[1].substring(0,split1[1].length-1);
                sendAddres.set(sendN,sendA);
                sendAddress.set(sendN,sendA);}
        }
    }
    //获取抄送人
    var cs=$("#ccpeople").val();//抄送人
    if(cs!="") {
        var ssj = cs.split(",");
        for (let i in ssj) {
            if (ssj[i].indexOf(substring) == -1) {
                copyAddress.push(ssj[i])
            } else {
                var split1 = ssj[i].split("<");
                var sendA = split1[1].substring(0, split1[1].length - 1);
                copyAddress.push(sendA);
            }
        }
    }
    if(deplay.forceCopy!=null){
        var fc=deplay.forceCopy.split(",")
        for(let i in fc){
            if(fc[i]!=""){
                copyAddress.push(fc[i]);
            }
        }
    }
    //密送
    var ms=$("#closesendpeople").val();//密送
    if(ms!="") {
        var ssj = ms.split(",");
        for (let i in ssj) {
            if (ssj[i].indexOf(substring) == -1) {
                darkAddress.push(ssj[i])
            } else {
                var split1 = ssj[i].split("<");
                var sendA = split1[1].substring(0, split1[1].length - 1);
                darkAddress.push(sendA);
            }
        }
    }
    if(deplay.Dark!=null){
        var fd=deplay.Dark.split(",")
        for(let i in fd){
            if(fd[i]!=""){
                copyAddress.push(fd[i]);
            }
        }
    }
    let adj= Object.create(null);
    for (let[k,v] of aduncts) {
        adj[k] = v;
    }
    let sda= Object.create(null);
    for (let[k,v] of sendAddres) {
        sda[k] = v;
    }
    let sdas= Object.create(null);
    for (let[k,v] of sendAddress) {
        sdas[k] = v;
    }
    var send=sendDate;
    var is=ismore;
    var message={
        "email_id":email_id,
        "sendDate":send,//发送时间
        "stmpId":pop,    //发送服务器id
        "charset":"UTF-8",//字符集
        "contenct":getDate(),//正文
        "pictures":pictures, //正文附图  map中，前为图片名,在正文中写法应为src=”cid:“，后为图片地址 Map<String,String>  在后端处理
        "aduncts":adj, //附件private Map<String,String>
        "ismore":is,//控制单发还是群发单显  1是单发，2是群发
        //单发属性
        "subject":subject,//主题
        "sendAddres":sda,//发送地址private Map<String,String>
        "copyAddress":copyAddress, //抄送地址private List<String>
        "darkAddress":darkAddress, //密送（暗送）地址private List<String>
        //群发属性
        "subjects":subjects,//private List<String>
        "sendAddress":sdas, //发送地址  key=用户名 value=地址private Map<String,String>
        "momStart":1,//发送间隔起点 秒
        "momEnd":10 //发送间隔终点 秒
    }
    return message;
}


function saveEmail() {
    var message = getEmail();
    $.ajax({
        url: 'email/saveEmail',
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(message),
        success: function (date) {
           layer.msg(date.data)
            window.location.reload();
        }
    });
}
//获取用户设置
function getdeploy() {
    $.ajax({
        url: 'email/showdeploy',
        type: 'GET',
        async: false, // 同步
        success: function (data) {
            deplay=data.data

        },
    });

}
//转发、回复控制器
var form = layui.form;
var caogao=0;
var answerOrRelay=0;//  =1为回复  =2转发
var answerOrRelayId=0;//控制标签修改
$(document).ready(function () {
    var t = $("#chaosong").text();
    if(t == '抄送') {
        $("#chaosong").text('删除抄送');
        $("#cxr").show();
    }
    getpop3ID()//获取smtpid
    getdeploy();
    //如果是回复邮件，触发
    var answer=getQueryString("answer");
    var emailID=getQueryString("emailID");
    answerOrRelayId=emailID
    if(answer!=null){
        answerOrRelay=1
        GetEmailForID(emailID,answer);
    }
    //如果是全部回复触发
    var Allanswer=getQueryString("Allanswer");
    if(Allanswer!=null){
        answerOrRelay=1
        GetEmailForIDAll(emailID,Allanswer)
    }
    //转发触发
    var relay=getQueryString("relay");
    if(relay!=null){
        if(relay==0){
            answerOrRelay=2
            GetEmailForID(emailID,3);
            $("#recipient").val("")
        }
    }
    var cao=getQueryString("caogao");
    if(cao==2){
        caogao=2;
        email_id=emailID;
        caogaoById(emailID,cao);
    }else if (cao==3){
        caogao=2;
        caogaoById(emailID,cao);
    }
    addcopyAndDark()
    form.render();
});

//添加默认抄送，密送
function addcopyAndDark() {
    if($("#closesendpeople").val()==""){
        if(deplay.defaultDark!=null){
            $("#closesendpeople").importTags(deplay.defaultDark)
        }
    }else{
        if(deplay.defaultDark!=null){
            var dark= $("#closesendpeople").val()+deplay.defaultDark
            $("#closesendpeople").importTags(dark)
        }
    }
   if( $("#ccpeople").val()==""){
       if(deplay.defaultCopy!=null){
           $("#ccpeople").importTags(deplay.defaultCopy)
       }

   }else{
       if(deplay.defaultCopy!=null){
      var cp= $("#ccpeople").val()+deplay.defaultCopy
       $("#ccpeople").importTags(cp)}
   }

}
//全部回复获取邮件元数据
function GetEmailForIDAll(emailID,answer) {
    $.ajax({
        url: 'email/showEmailbyIDLostUser',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async:false,
        data: {
            "emailID":emailID
        },
        success: function (date) {
            email=date.data
            //添加主题
            $(".emailSubject:eq(0)").val("RE:"+email.subject)
            if(email.email_class==5){//已发箱  发件人=发件人，收件人=收件人
                //添加发件人
                debugger
                var sendAdd= email.senderAddresser;
                $("#user-smtp").find("option[text='"+sendAdd+"']").attr("selected",true);
                form.render();
                //添加收件人
                var add = email.returnRecipientAddress;
                let newAdds = add.toString();
                var send = newAdds.replace(new RegExp(";","gm"),",")
                send=send.replace(new RegExp("&lt;","gm"),"<")
                send=send.replace(new RegExp("&gt;","gm"),">")
                var dar = email.returnDarkSendAddress.replace(new RegExp(";","gm"),",")
                var ccp = email.returnCopyAddress.replace(new RegExp(";","gm"),",")
                $("#recipient").importTags(send)
                $("#ccpeople").importTags(ccp)
                $("#closesendpeople").importTags(dar)
            }else{//其余箱
                //添加收件人
                debugger
                var Addres= email.charset;
                var adds=Addres.split(";")
                //2. 获取当前用户的所有smtp，如果吻合，放入
                var sendAdd="";
                for(let s1 in adds){
                    if(adds[s1]!=null){
                        for(let s2 in smtp){
                            if(adds[s1].toLowerCase()==smtp[s2].email_adress.toLowerCase()||adds[s1].toLowerCase()==smtp[s2].email_name.toLowerCase()){
                                sendAdd=smtp[s2].email_adress;
                            }
                        }
                    }
                }
                $("#user-smtp").find("option[text='"+sendAdd+"']").attr("selected",true);
                form.render();
                //添加发件人
                var add = email.returnRecipientAddress;
                let newAdds = add.toString();
                var send = email.senderAddresser+","+newAdds.replace(new RegExp(";","gm"),",")
                send=send.replace(new RegExp("&lt;","gm"),"<")
                send=send.replace(new RegExp("&gt;","gm"),">")
                var dar = email.returnDarkSendAddress.replace(new RegExp(";","gm"),",")
                var ccp = email.returnCopyAddress.replace(new RegExp(";","gm"),",")
                $("#recipient").importTags(send)
                $("#ccpeople").importTags(ccp)
                $("#closesendpeople").importTags(dar)
            }



            //type=0简单回复，1带全文回复，2带附件文回复
            if(answer!=0){
                getEmailAdjunct(emailID,answer)
            }
        },
    });
}
//普通回复获取邮件元数据
function GetEmailForID(emailID,answer) {
    $.ajax({
        url: 'email/showEmailbyID',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async:false,
        data: {
            "emailID":emailID
        },
        success: function (date) {
            email=date.data
            //添加主题

            if(answer!=3){
                var send=email.senderAddresser;
                send=send.replace(new RegExp("&lt;","gm"),"<")
                send=send.replace(new RegExp("&gt;","gm"),">")
                $("#recipient").importTags(send+",")
                //设置发件人   1获取该邮件收件人  以  ;  分割
                $(".emailSubject:eq(0)").val("RE:"+email.subject)
            }else{
                $(".emailSubject:eq(0)").val("FW:"+email.subject)
            }
            debugger
            var Addres= email.recipientAddress+";"+email.copyAddress;
            var adds=Addres.split(";")
            //2. 获取当前用户的所有smtp，如果吻合，放入
            var sendAdd="";
            for(let s1 in adds){
                if(adds[s1]!=null){
                    for(let s2 in smtp){
                        if(adds[s1].toLowerCase()==smtp[s2].email_adress.toLowerCase()||adds[s1].toLowerCase()==smtp[s2].email_name.toLowerCase()){
                            sendAdd=smtp[s2].email_adress;
                        }
                    }
                }

            }
            $("#user-smtp").find("option[text='"+sendAdd+"']").attr("selected",true);
            form.render();
            if(answer==3){
                answer=2;
            }
            if(answer!=0){
                getEmailAdjunct(emailID,answer)
            }


        },
    });
}
//草稿
function caogaoById(emailID,answer) {
    $.ajax({
        url: 'email/showEmailbyID',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        data: {
            "emailID": emailID,
            "isread":1
        },
        success: function (date) {
            debugger
            email = date.data
            //添加主题
            if(caogao==2||caogao==3){
               $(".emailSubject:eq(0)").val(email.subject)
            }else{
                $(".emailSubject:eq(0)").val("回复 :" + email.subject)
            }
            //添加收件人
            var add =email.recipientAddress;
            let newAdds = add.toString();
            var send = newAdds.replace(new RegExp(";", "gm"), ",")
            var dar = email.darkSendAddress.replace(new RegExp(";", "gm"), ",")
            var ccp = email.copyAddress.replace(new RegExp(";", "gm"), ",")
            $("#recipient").importTags(send)
            $("#ccpeople").importTags(ccp)
            $("#closesendpeople").importTags(dar)
            $("#user-smtp").find("option[text='"+  email.senderAddresser+"']").attr("selected",true);
            //添加抄送密送
            //type=0简单回复，1带全文回复，2带附件文回复
            if (answer != 0) {
                getEmailAdjunct(emailID, answer)
            }


        },
    });
}
//获取全部附件并处理
function getEmailAdjunct(emailID,answer) {
        $.ajax({
            url: 'email/showEmailAdjunctbyID',
            type: 'GET',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async:false,
            data: {
                "emailID":emailID
            },
            success: function (data) {
                var adjs = data.data;
                if(answer!=0){
                    for(let i in adjs){
                        if(adjs[i].isText==1){
                            addContext(adjs[i].textAddress)
                        }
                    }
                    if(answer==2||answer==3){
                        $.ajax({
                            url: 'email/answerAdjunct',
                            type: 'GET',
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            async:false,
                            data: {
                                "emailID":emailID
                            },
                            success: function (data) {
                                var add=new Map();
                                var data1 = data.data;
                                for(let i in data1){
                                    var name = data1[i].name
                                    var address=data1[i].address
                                    answerAddAdjuncts(name,address)
                                }

                            },
                        });
                    }
                }


            },
        });
}

//正文植入
function addContext(Adjcontext) {
    //添加正文
    var context = mathImg(Adjcontext);
    //对context进行处理，主要针对img，利用正则进行匹配


    //------------------ 原始邮件 ------------------
    // 发件人: "804422090" <804422090@qq.com>;
    // 发送时间: 2020年12月25日(星期五) 晚上9:35
    // 收件人: "爱飞生世"<1052152248@qq.com>;
    // 主题: 10521522
    var send=email.senderAddresser;
    var recipient=email.recipientAddress;
    var cont="<br>------------------ 原始邮件 ------------------<br>"+
        "发件人:"+send+"<br>"+
        "发送时间:"+email.sendDate+"<br>"+
        "收件人:"+recipient+"<br>"+
        "抄送人:"+email.copyAddress+"<br>"+
        "主题:"+email.subject+"<br>"+
        context;
    if(caogao==2){
        setDate(context)
    }else{
        setDate(cont);
    }


}
//获取附件
function answerAddAdjuncts(fileName,filePath) {
    //从ftp服务器下载到本地，在返回到前端。
        aduncts.set(fileName,filePath)
        fileNameIndex.set(fileIndex,fileName);
        layer.msg('上传成功');
    $("#adjuncts").append("<div class=\"item\" title='"+fileName+"' id='adjunct"+fileIndex+"'><div>\n" +
        "<img alt=\"\" src=\"statics/img/"+adjunctClass(fileName)+".png\">\n" +
        "</div><div style=\"padding:6px;\">\n" +
        "<p><a>"+fileName+"</a></p><div>\n" +
        "</div></div>\n" +
        "<a class=\"close\" onclick='deleteAdjunct(\""+fileName+"\")'>x</a></div>");
    fileIndex++;
}
//正则表达式匹配img
function mathImg(htmlstr) {
    let that = this;
    let urll='';
    $.ajax({
        url: 'email/selectWeb',
        type: 'GET',
        async:false,
        success: function (data) {
            urll=data.data;
        },
    });
    let regex3 = new RegExp(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi);
    let htmlstr1 = htmlstr.replace(regex3, function (match, capture) {
        let tmp = capture//原src
        if(tmp.startsWith("ftp/downloadimg")){
            capture = urll + tmp;//新src
        }else{
            capture =tmp;//新src
        }
        let regex11= new RegExp( /width=[\'\"]?([^\'\"]*)[\'\"]?/i);
        var  width=""
        let wid1 = match.replace(regex11, function (match, capture) {
            if(capture!=""||capture!=null){
                width=capture
            }
        })
        if(width!=""){
            width="width='"+width+"px'";
        }
        let regex12= new RegExp( /heigh=[\'\"]?([^\'\"]*)[\'\"]?/i);
        var heigh=""
        let wid2 = match.replace(regex12, function (match, capture) {
            if(capture!=""||capture!=null){
                heigh=capture
            }
        })
        if(heigh!=""){
            heigh="heigh='"+heigh+"px'";
        }
        var newStr ="<img src='" + capture+"'" +width+heigh+ ' alt="" />';
        return newStr;
    });
    regex3 = null;
    return htmlstr1;
}

//新增标签
function addTag(email_id,title,color){
    $.ajax({
        url: 'email/addTag',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {
            "emailID":email_id,
            "title":title,
            "color":color
        },
        success: function (data) {
            var tag= data.data.tag;
            var emailID= data.data.emailID;
            showBadgeWindow(emailID,tag)
        },
    });
}